package com.zhou.demo.interfaceclass;

import com.squareup.okhttp.OkHttpClient;
import com.zhou.demo.callback.LatestNewsCallback;
import com.zhou.demo.helper.HttpFail;
import com.zhou.demo.url.ZhihuUrl;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.http.body.RequestBody;
import org.xutils.x;

/**
 * Created by 11065 on 2016/8/4.
 */
public class LastestNewsConnect implements LatestNewsInterface {

    @Override
    public void getLastestNews(final LatestNewsCallback latestNewsCallback) {
     /*   OkHttpClient okHttpClient = new OkHttpClient();*/
        RequestParams params = new RequestParams(ZhihuUrl.NEWSLATEST);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                latestNewsCallback.onLatestNewsSuccess(result);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

                latestNewsCallback.onLatestNewsFail(HttpFail.onError(ex,isOnCallback));
            }

            @Override
            public void onCancelled(CancelledException cex) {


            }

            @Override
            public void onFinished() {

            }
        });

    }
}
